import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.image as img
from multilayer_perceptron import MultilayerPerceptron
import math
#dataset url https://pjreddie.com/projects/mnist-in-csv/
data = pd.read_csv('MLPractice\\dataset\\mnist\\mnist_train.csv')
train_data = data.sample(frac=0.8) 
train_X = train_data.values[:,1:]
train_y = train_data.values[:,0:1]
test_data = data.drop(train_data.index)
test_X = test_data.values[:,1:]
test_y = test_data.values[:,0:1]

nums_to_display = 25
num_cells = math.ceil(math.sqrt(nums_to_display))
plt.figure(figsize=(10,10))
for i in range(nums_to_display):
    digit_label = train_y[i][0]
    digit_pixels = train_X[i]
    image_size = int(math.sqrt(digit_pixels.shape[0]))
    frame = digit_pixels.reshape((image_size,image_size))
    plt.subplot(num_cells,num_cells,i+1)
    plt.imshow(frame,cmap='Greys')
    plt.title(digit_label)
plt.subplots_adjust(hspace=0.5)
plt.show()

neuron_nums = [784,25,10]
nn = MultilayerPerceptron(train_X,train_y,neuron_nums)
cost_history = nn.train(max_iter=200,alpha=0.1)
print(cost_history)
